
class LoadingUI extends egret.Sprite {

    public constructor() {
        super();
        this.createView();
    }
    private textField: egret.TextField;
    private createView(): void {
        //单独加载资源
        RES.getResByUrl("resource/assets/loadingBG.png", function (texture) {
            //添加背景
            var bg = new egret.Bitmap();
            bg.texture = texture;
            this.addChildAt(bg, 0);
        }, this);
        this.textField = new egret.TextField();
        this.addChild(this.textField);
        this.textField.y = 300;
        this.textField.width = 750;
        this.textField.textAlign = "center";
    }
    public setProgress(current: number, total: number): void {
        var percent = Math.ceil(current / total * 100);
        this.textField.text = `Loading...${percent}%`;
        //进度条背景矩形
        var jindutiaoBG = new egret.Shape();
        jindutiaoBG.graphics.beginFill(0x8aacdf);
        jindutiaoBG.graphics.drawRoundRect(250, 400, 250, 10, 0, 0);
        jindutiaoBG.graphics.endFill();
        this.addChild(jindutiaoBG);
        //进度条
        var jdt = new egret.Shape();
        jdt.graphics.beginFill(0xf21111);
        jdt.graphics.drawRoundRect(250, 400, 250 * percent * 0.01, 10, 0, 0);
        jdt.graphics.endFill();
        this.addChild(jdt);
    }
}
